using System;
using System.Collections.Generic;
using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay
{
    public class PlayerMoveStartCommand : PlayerCommand
    {
        public Vector2 dir = Vector2.zero;
        public override EPlayerCommandType type => EPlayerCommandType.MoveStart;

        public void Initialize(Vector2 dir)
        {
            this.dir = dir;
        }
        
        public override void Execute(UnitView entity)
        {
            var rCameraRotation = ManagerCenter.UI.MainCamera.transform.rotation;
            var rMoveDir = BattleClientUtil.ScreenDirToWorld(rCameraRotation, dir);

            var rCustom = entity.GetComponent<CustomPropertyViewComponent>(ETComponentType.CustomPropertyViewComponent);
            var rMove = entity.GetComponent<BattleMoveComponent>(ETComponentType.BattleMoveComponent);

            // rotationComponent.inputDirection = rMoveDir;
            if (rCustom == null || !rCustom.GetProperty<bool>(ECustomProperty.ForbidInputMove))
            {
                rMove.SetSpeedAspect(rMoveDir);
            }
        }

        public override void OnReset()
        {
            this.dir = Vector2.zero;
        }
        
        public override void Free()
        {
            ClassPool.Put(this);
        }
    }
}